﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSpace.Orgs;
using SmartSpace.Web;

namespace SmartSpace.WebApp.Modules.Orgs.Pages
{
    public partial class TypeRelation_Add : SsTemplatePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindNodeTypeList();
            }
        }

        public void BindNodeTypeList()
        {
            OrgsService service = new OrgsService();
            ListResult<NodeType> list = service.GetTypes();

            this.rep1.DataSource = list.Data;
            this.rep1.DataBind();
        }


        protected void btn_Save_Click1(object sender, EventArgs e)
        {
            Guid parentTypeId = new Guid(Request.QueryString["ParentTypeId"] ?? String.Empty);

            foreach (RepeaterItem item in rep1.Items)
            {
                CheckBox checkBox = (CheckBox)item.FindControl("checkNodeType");
                if (checkBox != null && checkBox.Checked)
                {
                    HiddenField hiddenField = (HiddenField)item.FindControl("nodeTypeId");
                    OrgsService service = new OrgsService();
                    service.IncludeSubType(parentTypeId, new Guid(hiddenField.Value));
                }
            }

            Response.Redirect("NodeType-List.aspx?ParentTypeId=" + parentTypeId.ToString());
        }
    }
}